<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*,java.text.DecimalFormat;
    "%>
<jsp:include page="common/header.jsp"></jsp:include>
<%
	UserSession usersession = (UserSession)session.getAttribute("user");
	String ent_id 			= (String)session.getAttribute("ent_id");
	
	String connGroup 	= "";
	String user_id 		= "";
	if(usersession!=null){
		connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
		user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
	}
	
	Calendar now = Calendar.getInstance();
	String year     = String.valueOf(now.get(Calendar.YEAR));
	String month    = String.valueOf(now.get(Calendar.MONTH)+1);
	String curDay   = String.valueOf(now.get(Calendar.DATE));
	
	if(month.length() == 1){
		month = 0 + month;
	}
	
	if(curDay.length() == 1){
		curDay = 0 + curDay;
	}

	now.add(Calendar.MONTH,-1);
	
	String b_year     = String.valueOf(now.get(Calendar.YEAR));
	String b_month    = String.valueOf(now.get(Calendar.MONTH)+1);
	String b_curDay   = String.valueOf(now.get(Calendar.DATE));
	
	if(b_month.length() == 1){
		b_month = 0 + b_month;
	}
	
	if(b_curDay.length() == 1){
		b_curDay = 0 + b_curDay;
	}
	
	String start_dt = CmmUtil.nvl(request.getParameter("start_dt"),b_year + b_month + b_curDay);
	String close_dt = CmmUtil.nvl(request.getParameter("close_dt"),year + month + curDay);
	/*
	String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
	//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
	String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
	String present_Date 	= String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));
	
	if(present_Month.length() == 1){
		present_Month = "0" + present_Month; //01월,02월 ..... 09월
	}
	
	GregorianCalendar g = new GregorianCalendar();
	g.add(Calendar.MONTH, 0);
	
	String befor_Month = String.valueOf(g.get(Calendar.MONTH));
	
	if(befor_Month.length() == 1){
		befor_Month = "0" + befor_Month; //01월,02월 ..... 09월
	}
	
	if(present_Date.length() == 1){
		present_Date = "0" + present_Date; //01일,02일 ..... 09일
	}
	
	String start_dt = CmmUtil.nvl(request.getParameter("start_dt"),present_Year + befor_Month + present_Date);
	String close_dt = CmmUtil.nvl(request.getParameter("close_dt"),present_Year + present_Month + present_Date);
	*/
	
	String poi_cd 	= CmmUtil.nvl(request.getParameter("poi_cd"),"");
	String kisu_id 	= CmmUtil.nvl(request.getParameter("kisu_id"),"");
	String class_no = CmmUtil.nvl(request.getParameter("class_no"),"");
	
	String lrg_cate = CmmUtil.nvl(request.getParameter("lrg_cate"),"");
	String mid_cate = CmmUtil.nvl(request.getParameter("mid_cate"),"");
	String sml_cate = CmmUtil.nvl(request.getParameter("sml_cate"),"");
	
	String cate_id = CmmUtil.nvl(request.getParameter("cate_id"),"");
	String cate_gubun = CmmUtil.nvl(request.getParameter("cate_gubun"),"");
 	
	HashMap map = new HashMap();
	HashMap map1 = null;
	HashMap map2 = null;
	HashMap map3 = null;
	
	ArrayList list = new ArrayList();
	ArrayList list1 = new ArrayList();
	ArrayList list2 = new ArrayList();
	ArrayList list3 = new ArrayList();
	CommonDaoService commonservice = new CommonDaoService("Com0102lp04Dao");
	
	//과목리스트
	map.put("ent_id",ent_id);
	map.put("start_dt",start_dt);
	map.put("close_dt",close_dt);
	
	map.put("cate_id",cate_id);
	map.put("cate_gubun",cate_gubun);
	
	//설문결과
	map.put("poi_cd",poi_cd);
	map.put("kisu_id",kisu_id);
	map.put("class_no",class_no);
	
	map.put("connGroup",connGroup);
	map.put("user_id",user_id);
	
	list = (ArrayList)commonservice.commonDaoMethod(map);
	
	if(list != null){
		if(list.size() > 0){
			list1 = (ArrayList)list.get(0);
		}
		if(list.size() > 1){
			list2 = (ArrayList)list.get(1);
		}
		if(list.size() > 2){
			list3 = (ArrayList)list.get(2);
		}
	}
	
	
	
%>
<script language='javascript' src="/js/ajaxutil.js"></script>
<script>
	function select_Change(value){
		var array = value.split(",");
		var frm = document.frm1;
		
		frm.poi_cd.value 	= value;
		//frm.kisu_id.value 	= array[1];
		//frm.class_no.value 	= array[2];
		
		frm.method ="post";
		frm.target ="_self";
		frm.action ="com0102l_p04.jsp";
		frm.submit();
	}
	
	function search(){
		var frm = document.frm1;
		frm.poi_cd.value = frm.poi_nm_select.value;
		
		frm.method ="post";
		frm.target ="_self";
		frm.action ="com0102l_p04.jsp";
		frm.submit();
	}

	function init(){ 
        form = document.frm1;
      
        setCateList(form.lrg_cate,'<%=lrg_cate%>', '선택', '000|lrg');
        setCateList(form.mid_cate,'<%=mid_cate%>', '선택', '<%=lrg_cate%>|mid');
		setCateList(form.sml_cate,'<%=sml_cate%>', '선택', '<%=mid_cate%>|sml');
	}

	function go_change_cate(v, gu){
		form = document.frm1;
		
		if(gu == "lrg"){
			setCateList(form.mid_cate,'', '선택', v+'|mid');
			setCateList(form.sml_cate,'', '선택', '');			
		}else if(gu== "mid"){
			setCateList(form.sml_cate,'', '선택', v+'|sml');
		}else if(gu== "sml"){
		}

		form.cate_id.value = v;
		form.cate_gubun.value = gu;

		var start_dt = form.start_dt.value;
		var close_dt = form.close_dt.value;

		//setPoiList(form.poi_nm_select,'', '과정선택', v,gu,start_dt,close_dt);
	}
</script>
<body onload="init()">
<table width="992" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td>
    <!--top -->
    <jsp:include page="common/top_menu.jsp"></jsp:include>
    <!-- //top -->
    <!-- contents area -->
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="180" valign="top">
		<jsp:include page="left/com0101l_p05.jsp"></jsp:include>
    </td>
    <td width="21" valign="top">&nbsp;</td>
    <td valign="top">
    
<form name="frm1">
	<input type="hidden" name="poi_cd" value="<%=poi_cd %>">
	<input type="hidden" name="kisu_id" value="<%=kisu_id %>">
	<input type="hidden" name="class_no" value="<%=class_no %>">
	<input type="hidden" name="cate_id" value="<%=cate_id %>">
	<input type="hidden" name="cate_gubun" value="<%=cate_gubun %>">

    	 <table width="790px"  border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="font-size:14px; color:#3b70a2; font-weight:bold; border-bottom:2px solid #c8c8c8; padding:0 0 5px 0;" align="left"><img src="/images/sub_icon1.jpg"  alt="" border="0">&nbsp;학습관리 - 설문결과</td>
            </tr>
			<tr><td height=5></td></tr>
            <tr>
            	<td align=left>
					분류별 : 
					<select name="lrg_cate" onchange="go_change_cate(this.value, 'lrg');"> </select>
					<select name="mid_cate" onchange="go_change_cate(this.value, 'mid');"></select>
					<select name="sml_cate" onchange="go_change_cate(this.value, 'sml');"></select>
                    &nbsp;&nbsp;&nbsp;&nbsp;
					과정별 : 
					<select id="poi_nm_select" name="poi_nm_select" onchange="javascript:select_Change(this.value)" >
					<option value="">과정선택</option>
					<%if(list1 != null && list.size() > 0){ %>
						<%for(int i=0; i<list1.size(); i++){
							map1 = (HashMap)list1.get(i);
							
							/*
							String Value = map1.get("poi_cd") + "," + map1.get("kisu_id") + "," + map1.get("class_no");
							String SelectedValue = poi_cd + "," + kisu_id + "," + class_no;
							*/
							String Value = map1.get("poi_cd").toString() ;
							String SelectedValue = poi_cd ;
						%>
                 		<option value="<%=Value%>" <%if(SelectedValue.equals(Value)){ %> selected<%} %>>
                 			<%=map1.get("poi_nm") %>
                 		</option>
                 		<%} %>
                 	<%}else{ %>
                 		<option value="">과목없음</option>
                 	<%} %>
               		</select>
            	</td>
			</tr>
			<tr><td height=5></td></tr>
			<tr>
				<td align="right">검색일자
					<input type="text" name="start_dt" id="start_dt" class="textbox"  value="<%=start_dt %>"/>
					<script language=javascript>
						var basicCal = new calendar("FIELD:document.frm1.start_dt;FORMAT:2;DELIMITER:;");
						basicCal.writeCalendar();
					</script>
						~
					<input type="text" name="close_dt" id="close_dt" class="textbox"  value="<%=close_dt %>"/>
					<script language=javascript>
						var basicCal = new calendar("FIELD:document.frm1.close_dt;FORMAT:2;DELIMITER:;");
						basicCal.writeCalendar();
					</script>
					<a href="javascript:search()">
						<img src="/images/bt_search2.gif" align="absmiddle" />
					</a>             
				</td> 
            </tr>
        </table>
        <table width="790px"  border="0" cellpadding="0" cellspacing="0">
         <tr>
        	<td>
            	<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="main_table4">
                  <tr>
                   
                    <td class="table_th">학습자</td>
                    <td class="table_th">과정수</td>
                    <td class="table_th">응시자</td>
                    <td class="table_th">응시율</td>
                  </tr>
                  <%if(list3 != null && list3.size() > 0){
                	  map3 = (HashMap)list3.get(0);
                	  
                	  String member_count = CmmUtil.nvl((String)map3.get("member_count"),"0");
                	  String poi_count 	  = CmmUtil.nvl((String)map3.get("poi_count"),"0");
                	  String apply_count  = CmmUtil.nvl((String)map3.get("apply_count"),"0");
                	  
                	  int m_count = Integer.parseInt(member_count);
                	  int a_count = Integer.parseInt(apply_count);
                	  double apply_persent = a_count / (double)m_count ;
                	  //System.out.println("응시율==========>"+apply_persent);
                	  apply_persent= apply_persent*100;
                	  
                	  DecimalFormat df = new DecimalFormat("###.##");
                	  //df.format(apply_persent);
                  %>
                  <tr>
                    
                    <td><%=member_count %></td>
                    <td><%=poi_count %></td>
                    <td><%=apply_count %></td>
                    <td><%=df.format(apply_persent) %>%</td>
                  </tr>
                  <%}else{ %>
                  <tr>
                  	<td colspan="5"></td>
                  </tr>
                  <%} %>
                </table>
            </td>
        </tr>
        <tr>
        	<td align="right"><!--  input type="image" src="/images/btn_save_excel2.gif" align="absmiddle" / --></td>
        </tr>
        <tr>
            <td colspan="5" style="padding:0 0 5px 0;" align="left"><img src="/images/line_member.gif"  alt="" border="0"></td>
        </tr>
        </table>
        
     <%

	if(list2 != null && list2.size() > 0){
		 String kinname[] = {"과정설문","강사설문","시스템설문"};
    	 String q_title 			= "";
    	 String opinion_quest_gb 	= "";
    	 String opinion_quest_type 	= "";
    	 String opinion_quest_type2 = "";
    	 String answer1				= "";
    	 String answer2				= "";
    	 String answer3				= "";
    	 String answer4				= "";
    	 String answer5				= "";
    	 String result_graph1 		= "";
    	 String result_graph2 		= "";
    	 String result_graph3 		= "";
    	 String result_graph4 		= "";
    	 String result_graph5 		= "";
    	 String comment				= "";
    	 
 		for(int i =0; i<list2.size(); i++){
    	 	map2 = (HashMap)list2.get(i);
    	 	answer1 			= (String)map2.get("opinion_sub_1");
    	 	answer2 			= (String)map2.get("opinion_sub_2");
    	 	answer3 			= (String)map2.get("opinion_sub_3");
    	 	answer4 			= (String)map2.get("opinion_sub_4");
    	 	answer5 			= (String)map2.get("opinion_sub_5");
    		q_title				= (String)map2.get("opinion_quest_title");
    		opinion_quest_gb  	= (String)map2.get("opinion_quest_gb"); // 1 or 2 or 3
    		opinion_quest_type 	= (String)map2.get("opinion_quest_type");
    		result_graph1 		= (String)map2.get("result_graph1");
    		result_graph2 		= (String)map2.get("result_graph2");
    		result_graph3 		= (String)map2.get("result_graph3");
    		result_graph4 		= (String)map2.get("result_graph4");
    		result_graph5 		= (String)map2.get("result_graph5");
    		comment 			= (String)map2.get("cnt0");

     %>
     <!--  과정 설문  Start -->
<% 			if (!opinion_quest_type.equals("2")){ %>
<!-- 	<table width="790px" border="0" cellpadding="0" cellspacing="0" style="margin:3px 0 0 0">
		<tr>
			<td class="main_style1" style="padding:5px 0 0 0;" align="left"><img src="/images/hrd_icon2.gif"  alt="" border="0" style="padding:0 0 0 7px;"/>&nbsp;과정설문</td>
		</tr>
	</table>
-->	
     <table width="790px" border="0" cellpadding="0" cellspacing="0" class="bbs_property" summary="" style="font-size:11px; margin:13px 0 20px 0;">
     	<tr>
         <td width="50px" style="background:#e6e6e6;"><%=i+1 %></td>
         <td colspan="4" align="left" style="background:#e6e6e6; padding:0 0 0 10px;"><%=q_title%></td>
		 <td align="right" style="background:#e6e6e6; padding:0 10px 0 10px;"><%=kinname[Integer.parseInt(opinion_quest_gb)-1]%></td>
        </tr>
	
        <tr>
        	<td rowspan="2"></td>
        	<td width=19% align="left"><%=result_graph1 %></td>
        	<td width=19% align="left"><%=result_graph2 %></td>
        	<td width=19% align="left"><%=result_graph3 %></td>
        	<td width=19% align="left"><%=result_graph4 %></td>
        	<td width=19% align="left"><%=result_graph5 %></td>
        </tr>
        <tr>
            <td width=19%><%=answer1%></td>
			<td width=19%><%=answer2%></td>
			<td width=19%><%=answer3%></td>
			<td width=19%><%=answer4%></td>
			<td width=19%><%=answer5%></td>
        </tr>
	</table>
	<%		}else{ 
				if (!opinion_quest_type.equals(opinion_quest_type2)){%>
	  <table width="790px" border="0" cellpadding="0" cellspacing="0" class="bbs_property" summary="" style="font-size:11px; margin:13px 0 20px 0;">
     	<tr>
         <td width="50px" style="background:#e6e6e6;"><%=i+1 %></td>
         <td width="600px" align="left" style="background:#e6e6e6; padding:0 0 0 10px;"><%=q_title%></td>
		 <td width="140px" align="right" style="background:#e6e6e6; padding:0 10px 0 10px;"><%=kinname[Integer.parseInt(opinion_quest_gb)-1]%></td>
        </tr>
        <tr>
			<td></td>            
			<td colspan="2" width=95% align="left" style="padding:0 0 0 10px;"><%=comment%></td>
        </tr>
		</table>
		<%			}else{ %>
		<tr>
			<td></td>            
			<td colspan="2" width=95% align="left" style="padding:0 0 0 10px;"><%=comment%></td>
        </tr>
    <%				}
    			}
				opinion_quest_type2 = opinion_quest_type;
			}
		}else{
    %>	
	  <table width="790px" border="0" cellpadding="0" cellspacing="0" class="bbs_property" summary="" style="font-size:11px; margin:13px 0 20px 0;">
		<tr>
			<td colspan="2">설문이 없습니다</td>
		</tr>
	  </table>
	<%} %>
     <!--  과정 설문 End -->
     
	
</form>
     </td>
    </tr>
	</table>

   
		<jsp:include page="common/footer.jsp"></jsp:include>
	</td>
  </tr>
</table>
</body>
</html>
